home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-21 | 3.2 KB | 117 lines | [TEXT/CWIE] |
- // ===========================================================================
- // COffScreenPicture.cp
- //
- // ©1997 Maxym Runov. All rights reserved.
- //
- // You are free to use this code in any project,
- // but the copyright remains with me.
- // Any questions and notes are welcome.
- //
- // E-mail: max@sunbay.crimea.ua
- // ===========================================================================
- // Version 2.0
-
- #include <LStream.h>
- #include "COffScreenPicture.h"
-
-
- // ---------------------------------------------------------------------------
- // Constructor
- // ---------------------------------------------------------------------------
-
- COffScreenPicture::COffScreenPicture(LStream *inStream) : LView(inStream){
- mGWorld = 0;
-
- inStream->ReadData(&mPICTid, sizeof(ResIDT));
- SetPictureID(mPICTid);
- };
-
-
- // ---------------------------------------------------------------------------
- // Destructor
- // ---------------------------------------------------------------------------
-
- COffScreenPicture::~COffScreenPicture(void){
- if(mGWorld) delete mGWorld;
- };
-
-
- #pragma mark -
-
-
- // ---------------------------------------------------------------------------
- // GetPictureID
- // ---------------------------------------------------------------------------
- // Return the PICT Resource ID associated with a Picture
-
- ResIDT COffScreenPicture::GetPictureID(void){
- return mPICTid;
- }
-
-
- // ---------------------------------------------------------------------------
- // SetPictureID
- // ---------------------------------------------------------------------------
- // Set the PICT Resource ID associated with a Picture
-
- void COffScreenPicture::SetPictureID(ResIDT inPictureID){
- if(mGWorld) delete mGWorld;
- ResizeImageTo(0, 0, false);
-
- mPICTid = inPictureID;
- PicHandle hpic = ::GetPicture(mPICTid);
- if(hpic){
- HLock((Handle)hpic);
- Rect rect = (*hpic)->picFrame;
- rect.right -= rect.left;
- rect.bottom -= rect.top;
- rect.left = 0;
- rect.top = 0;
-
- mGWorld = new LGWorld(rect, 32);
- if(mGWorld){
- mGWorld->BeginDrawing();
- ::DrawPicture(hpic, &rect);
- mGWorld->EndDrawing();
- ResizeImageTo(rect.right, rect.bottom, false);
- }
- HUnlock((Handle)hpic);
- ReleaseResource((Handle)hpic);
- }
- }
-
-
- #pragma mark -
-
-
- // ---------------------------------------------------------------------------
- // DrawSelf
- // ---------------------------------------------------------------------------
-
- void COffScreenPicture::DrawSelf(void){
- if(!mGWorld) return;
- RgnHandle localUpdateRgnH = GetLocalUpdateRgn();
- if(!EmptyRgn(localUpdateRgnH)){
- ApplyForeAndBackColors();
- Rect updateRect = (**localUpdateRgnH).rgnBBox;
- Rect portRect = (mGWorld->GetMacGWorld())->portRect;
-
- ::EraseRect(&updateRect);
- if(updateRect.right > portRect.right) updateRect.right = portRect.right;
- if(updateRect.bottom > portRect.bottom) updateRect.bottom = portRect.bottom;
-
- ::LockPixels(::GetGWorldPixMap(mGWorld->GetMacGWorld()));
- ::LockPixels(::GetGWorldPixMap((CGrafPtr)GetMacPort()));
-
- ApplyForeAndBackColors();
- ::CopyBits((BitMapPtr)&((mGWorld->GetMacGWorld())->portPixMap),
- &(GetMacPort())->portBits,
- &updateRect, &updateRect, srcCopy, nil);
-
- ::UnlockPixels(::GetGWorldPixMap(mGWorld->GetMacGWorld()));
- ::UnlockPixels(::GetGWorldPixMap((CGrafPtr)GetMacPort()));
- }
- ::DisposeRgn(localUpdateRgnH);
- }
-
-